<?php
namespace Plu\qdh\Models\App;

use Phalcon\Mvc\Model;

class Report extends Model
{

    // CREATE TABLE `report` (
    //     `id` int(11) NOT NULL AUTO_INCREMENT,
    //     `day` datetime NOT NULL COMMENT '结算日期',
    //     `custId` int(11) NOT NULL DEFAULT '0' COMMENT '分销商ID， 0代表自营',
    //     `totalNum` int(11) NOT NULL COMMENT '付款总订单',
    //     `totalPrice` decimal(12,2) NOT NULL COMMENT '付款总金额',
    //     `totalSettlementPrice` decimal(12,2) NOT NULL COMMENT '付款总分销价',
    //     `redoundTotalNum` int(11) NOT NULL COMMENT '退款总订单',
    //     `refoundTotalPrice` decimal(12,2) NOT NULL COMMENT '退款总额',
    //     `refoundtotalSettlementPrice` decimal(12,2) NOT NULL COMMENT '退款总分销价',
    //     PRIMARY KEY (`id`)
    //   ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4

    public function initialize() {
        $this->setConnectionService('db.qdh');
    }

    public function getSource() {
		return "report";
    }


    static public function getReport($custId, $startTime, $endTime) {
        
        $where = [
            'conditions' => " custId = :custId: AND day >= '$startTime' AND day <= '$endTime' ",
            'bind' => [
                'custId' => $custId
            ]
        ];

        $items = self::find($where);

        if ($items) {
            $items = $items->toArray();
            return $items;
        }

        return [];
        
    }



}